package com.lc.qianrenshiye.adapter;

import android.content.Context;
import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.lc.qianrenshiye.R;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/7.
 */
public class MyPagerAdapter extends PagerAdapter{

    private Context context;
    private List<ImageView> viewList = new LinkedList<>();

    public MyPagerAdapter(Context context, List<ImageView> viewList) {

        this.viewList = viewList;

        this.context = context;

    }

    @Override
    public int getCount() {
        return 1000;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        if (viewList.size() > 0) {

            position %= viewList.size();

            if (position < 0) {

                position = viewList.size() + position;
            }

            ImageView view = viewList.get(position);

            GlideLoader.getInstance().get(context, view.getTag().toString(), view, R.mipmap.banner_holder);

            ViewParent vp =view.getParent();

            if (vp!=null){

                ViewGroup parent = (ViewGroup)vp;
                parent.removeView(view);

            }

            container.addView(view);

            return view;

        }

        return null;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

//        container.removeView(viewList.get(position % viewList.size()));

    }



}
